// app.js
const publicParams = require("utils/publicParams");
const publicMethods = require("./utils/publicMethods");
const $api = require("./service/index").default;
const $http = require("./http/index").default;
wx.$api = $api;
wx.$http = $http;

App({
    onLaunch() {
        // 展示本地存储能力
        var userInfo = wx.getStorageSync('userInfo');
        if(!userInfo) {
             // 登录
            wx.login({
                success: res => {
                    wx.$http.post(wx.$api.fetchLogin, {code: res.code}).then(res => {
                        wx.setStorageSync("userInfo", JSON.stringify(res));
                    })
                }
            })
        } else {
            this.globalData.userInfo = JSON.parse(userInfo);
        }
        // 获取用户信息
        wx.getSetting({
            success: res => {
                if (res.authSetting['scope.userInfo']) {
                    publicMethods.updateUserInfo(this);
                }
            }
        })
    },
    globalData: {
        userInfo: null,
        globalQiniuImgUrl: publicParams.baseImgUrl
    }
})